@@include('../base.html')
<script src="/assets/js/admin/top.js"></script>

<script>
    $(function() {
        // 全局设置token
        $.ajaxSetup({
            beforeSend: function(xhr) {
                //    读取内存的token
                const token = localStorage.getItem('token');
                //   将token设置进请求头中
                xhr.setRequestHeader('Authorization', token);
            },
            timeout: 10000
        });

        /* 获取用户登录状态 */
        $.ajax(baseUrl + '/login/status', {
            success: (res) => {
                // console.log('用户登录状态获取：', res);
                //已登录
                if (res.data && res.data.isLogin) {
                    console.log('已登录');
                    window.userId = res.data.userId;
                } else {
                    console.log('未登录');
                    location.href = '/admin/login.html';
                }
            },
            Error: (err) => {
                console.log('登录校验失败！');
                alert('登录失效！')
                location.href = 'login.html'
                console.log('错误信息：', err);
            }
        });

    });
</script>